package advanced.io;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/**
 * 字符,编码
 */
public class L_Character {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String msg = "性命,生命,使命a";
        //字节数组
        byte[] datas = msg.getBytes();//默认使用工程使用的字符集
        System.out.println(datas.length);

        //还原,解码:字符串
        msg = new String(datas, 0, datas.length, "utf-8");
        System.out.println(msg);
        msg = new String(datas, 0, datas.length - 1, "gbk");
        System.out.println(msg);
        //编码:其他字符集
        datas = msg.getBytes(Charset.forName("UTF-16lE"));
        System.out.println(datas.length);

    }
}
